< previous page page_358 next page >

Page 358
Listing 9.22. continued
    strWSName = "wsODBCDirect"
    strCOName = "TDPConnection"
    strDSN = "DSN=MS Access 7.0 Database;"
    strDBQ = "DBQ=C:\TYSDBVB5\Source\Data\Books5.mdb"
    strCOConnect = "ODBC;" & strDSN & strDBQ
    '
    ' create ws for ODBCDirect
    Set ws = DBEngine.CreateWorkspace(strWSName, "admin", "", dbUseODBC)
    '
    ' open a connection
    Set co = ws.OpenConnection(strCOName, dbDriverNoPrompt, False, strCOConnect)
    '
    ' show properties of connection object
    ' connection objects *do not* have a properties collection!
    strMsg = strMsg & "Name = " & co.Name & vbCrLf
    strMsg = strMsg & "Connect = " & co.Connect & vbCrLf
    strMsg = strMsg & "Database = " & co.Database.Name & vbCrLf
    strMsg = strMsg & "QueryTimeOut = " & co.QueryTimeout & vbCrLf
    strMsg = strMsg & "RecordsAffected = " & co.RecordsAffected & vbCrLf
    strMsg = strMsg & "StillExecuting = " & co.StillExecuting & vbCrLf
    strMsg = strMsg & "Transactions = " & co.Transactions & vbCrLf
    strMsg = strMsg & "Updatable = " & co.Updatable & vbCrLf
    '
    MsgBox strMsg, vbInformation, "Connection"
    '
    ' clean up
    co.Close
    ws.Close
    Set co = Nothing
    Set ws = Nothing
    '
End Sub
In the code in Listing 9.22, you first create a workspace object with the dbUseODBC parameter added. This creates the ODBCDirect-type workspace. Next, the code performs the Open Connection method on the workspace using the Connect string built-in program variables. This Connect string uses the default Microsoft Access driver that ships with Microsoft Office 95 or later. Notice that you are actually pointing to the BOOKS5.MDB database used throughout this book. Another key point to notice is that you are now using Visual Basic DAO to open an Access database. This is not possible if you are using the standard Microsoft Jet ODBC connection.
Tip.gif
You can now use ODBCDirect to open any ISAM-type database formats, including dBASE, FoxPro, Paradox, and so on, along with Microsoft Access and the back-end RDBMS formats such as SQL Server and Oracle.

 
< previous page page_358 next page >

If you like this book, buy it!